package com.ruoyi.base.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import com.ruoyi.base.domain.bo.BaseBsBdzdBo;
import com.ruoyi.base.domain.vo.BaseBsBdzdVo;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaCheckLogin;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.base.domain.vo.BaseBsZdVo;
import com.ruoyi.base.domain.bo.BaseBsZdBo;
import com.ruoyi.base.service.IBaseBsZdService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 站点
 *
 * @author zxs
 * @date 2024-09-25
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/base/bsZd")
public class BaseBsZdController extends BaseController {

    private final IBaseBsZdService iBaseBsZdService;

    /**
     * 查询站点列表
     */
    @SaCheckLogin
    @GetMapping("/list")
    public TableDataInfo<BaseBsZdVo> list(BaseBsZdBo bo, PageQuery pageQuery) {
        return iBaseBsZdService.queryPageList(bo, pageQuery);
    }

    /**
     * 查询站点管理列表不分页
     */
    @SaCheckLogin
    @GetMapping("/getList")
    public R<List<BaseBsZdVo>> getList(BaseBsZdBo bo) {
        return R.ok(iBaseBsZdService.queryList(bo));
    }

    /**
     * 导出站点列表
     */
    @SaCheckLogin
    @Log(title = "站点", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(BaseBsZdBo bo, HttpServletResponse response) {
        List<BaseBsZdVo> list = iBaseBsZdService.queryList(bo);
        ExcelUtil.exportExcel(list, "站点", BaseBsZdVo.class, response);
    }

    /**
     * 获取站点详细信息
     *
     * @param id 主键
     */
    @SaCheckLogin
    @GetMapping("/{id}")
    public R<BaseBsZdVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iBaseBsZdService.queryById(id));
    }

    /**
     * 新增站点
     */
    @SaCheckLogin
    @Log(title = "站点", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody BaseBsZdBo bo) {
        return toAjax(iBaseBsZdService.insertByBo(bo));
    }

    /**
     * 修改站点
     */
    @SaCheckLogin
    @Log(title = "站点", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody BaseBsZdBo bo) {
        return toAjax(iBaseBsZdService.updateByBo(bo));
    }

    /**
     * 删除站点
     *
     * @param ids 主键串
     */
    @SaCheckLogin
    @Log(title = "站点", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iBaseBsZdService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
